﻿using System;
using System.Linq;

namespace TMIS.DAL
{
    public class Department
    {
        private Model.ThesisDB db = new Model.ThesisDB();

        #region 对院系表查询数据功能的实现
        /// <summary>
        /// 获取院系表中所有院系的名称
        /// </summary>
        /// <returns></returns>
        public string[] Search()
        {
            string[] department = (from d in db.Department
                                   select d.Name).ToArray();
            return department;
        }

        /// <summary>
        /// 获取指定院系名称对应的ID号
        /// </summary>
        /// <param name="department">院系名称</param>
        /// <returns></returns>
        public Guid Search(string department)
        {
            Guid guid = (from d in db.Department
                         where d.Name == department
                         select d.ID).FirstOrDefault();
            return guid;
        }
        #endregion

        #region 对院系表插入数据功能的实现
        /// <summary>
        /// 将院系信息数据写入到院系表中
        /// </summary>
        /// <param name="department"></param>
        public void Insert(Model.Department department)
        {
            db.Department.InsertOnSubmit(department);
            db.SubmitChanges();
        }
        #endregion

        #region 对院系表删除数据功能的实现
        /// <summary>
        /// 删除指定的院系信息数据
        /// </summary>
        /// <param name="department"></param>
        public void Delete(string department)
        {
            Model.Department dep = db.Department.Single(e => e.Name == department);
            db.Department.DeleteOnSubmit(dep);
            db.SubmitChanges();
        }
        #endregion
    }
}
